package com.hello.controller;

import com.hello.model.Product;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.List;
//import org.springframework.web.bind.annotation.RestController;

/**
 *
 * @author Mordecai
 * @version 1.0.0
 * @blog http://blog.didispace.com
 *
 */
@Controller
public class ViewController {
    
//    @ResponseBody
    @RequestMapping("/hello")
    public String index() {
        System.out.println(">> ViewController.index() is called!");
        return "Hello World";
    }

//    @ResponseBody
    @RequestMapping("/fruits1")
    public String index1(ModelMap map) {
        System.out.println(">> ViewController.index1() is called!");
        map.addAttribute("hello", "Hello Thymeleaf!");
        return "index1";
    }

    @RequestMapping("/fruits2")
    public String index2(ModelMap map) {
        Product product = new Product("watermelon", 15.00);

        List<Product> list = new ArrayList<>();
        list.add(new Product("Apple", 11.00));
        list.add(new Product("Banana", 12.15));
        list.add(new Product("Peach", 13.14));

        map.addAttribute("product", product);
        map.addAttribute("allProducts", list);

        return "index2";
    }

}